<!DOCTYPE html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/gamepad-helpers.js"></script>
<script>

promise_test(async (t) => {
    assert_inherits(navigator, 'getGamepads');
    assert_own_property(window, 'GamepadEvent');

    let gamepads = navigator.getGamepads();
    assert_equals(gamepads.length, 4, 'gamepads.length');
    assert_equals(gamepads[0], null, 'gamepads[0]');

    let connectPromise = ongamepadconnected(t);
    gamepadController.connect(0);
    gamepadController.setId(0, "MockStick 3000");
    gamepadController.setButtonCount(0, 1);
    gamepadController.setAxisCount(0, 1);
    gamepadController.dispatchConnected(0);
    await connectPromise;

    let gamepad = navigator.getGamepads()[0];
    assert_not_equals(gamepad, null, 'gamepad');
    assert_true(gamepad.connected, 'gamepad.connected');
    assert_class_string(gamepad, 'Gamepad', 'gamepad');
    assert_class_string(gamepad.id, 'String', 'gamepad.id');
    assert_class_string(gamepad.connected, 'Boolean', 'gamepad.connected');
    assert_class_string(gamepad.index, 'Number', 'gamepad.index');
    assert_class_string(gamepad.timestamp, 'Number', 'gamepad.timestamp');
    assert_class_string(gamepad.axes, 'Array', 'gamepad.axes');
    assert_class_string(gamepad.axes[0], 'Number', 'gamepad.axes[0]');
    assert_class_string(gamepad.buttons, 'Array', 'gamepad.buttons');
    assert_class_string(gamepad.buttons[0].pressed, 'Boolean', 'gamepad.buttons[0].pressed');
    assert_class_string(gamepad.buttons[0].value, 'Number', 'gamepad.buttons[0].value');
    assert_class_string(gamepad.mapping, 'String', 'gamepad.mapping');
    assert_true(Object.isFrozen(gamepad.axes), 'gamepad.axes frozen');
    assert_true(Object.isFrozen(gamepad.buttons), 'gamepad.buttons frozen');
}, "Validates the exposed Gamepad API.");

</script>
</body>
